package 线程同步.修改不安全的案例.juc并发编程;

import java.util.concurrent.CopyOnWriteArrayList;

public class joc线程安全类型的集合 {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String> sum = new CopyOnWriteArrayList<String>();
        for (int i = 0; i < 100000; i++) {
            new Thread(()->{
                sum.add(Thread.currentThread().getName());
            }).start();

        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(sum.size());
    }
}
